package cn.com.homeyoda.aimate.aihealth.manager;

import android.text.TextUtils;

import com.wzq.mvvmsmart.utils.SPUtils;

import cn.com.homeyoda.aimate.aihealth.utils.AppConstants;

public class LoginStateManager {

    private static LoginStateManager instance;
    private boolean isLogin;

    private LoginStateManager() {
        // 只在初始化时读取一次 SP
        isLogin = !TextUtils.isEmpty(SPUtils.getInstance().getString(AppConstants.USER_ID));
    }

    public static LoginStateManager getInstance() {
        if (instance == null) {
            instance = new LoginStateManager();
        }
        return instance;
    }

    public boolean isLogin() {
        return isLogin;
    }

    public void login(String userId) {
        SPUtils.getInstance().put(AppConstants.USER_ID, userId);
        isLogin = true;
    }

    public void logout() {
        SPUtils.getInstance().remove(AppConstants.USER_ID);
        isLogin = false;
    }
}
